//
//  ConsultDocListViewController.m
//  安好
//
//  Created by lianchuang on 14/11/12.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "ConsultDocListViewController.h"
#import "ConsultDocListCell.h"
#import "UIImageView+AFNetworking.h"
#import "DocInfoViewController.h"
#import "ConsultViewController.h"
#import "DoctorTableViewCell.h"
#import "DocInfoViewController.h"
#import "LeftViewCell.h"

@interface ConsultDocListViewController ()<FKSearchBarDelegate,UIAlertViewDelegate>

// 控制线条的
@property (nonatomic, strong) UIView *transverseLineView;
@property (nonatomic, strong) UIView *shotVerticalLineView;
@property (nonatomic, strong) UIView *longVerticalLineView;
@end

@implementation ConsultDocListViewController
{
    NSString *keyword;
    FKSearchBar *illSeachBar;
    NSInteger leftControlRight;
    BOOL change;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.page=0;
    self.navigationItem.title=@"指定医生";
    UIBarButtonItem *backImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backClicked)];
    backImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backImg;
    [self makeRightFilterItem];

    self.tableview.dataSource=self;
    self.tableview.delegate=self;
    self.automaticallyAdjustsScrollViewInsets = NO;

    self.tableview.frame=CGRectMake(0, 44, kScreenWidth, kScreenHeight-64-44);
    self.tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.tableview addFooterWithTarget:self action:@selector(loadAllDoctors)];
    [self.tableview addHeaderWithTarget:self action:@selector(loadAllDoctorspage)];
    [self markIllnessSearchBar];

    [self makeTableView];
    leftControlRight = 100;
    change = YES;
    self.doctorsArrays=[[NSMutableArray alloc]init];
    //定位
    if ([CLLocationManager locationServicesEnabled]) {
        self.locationManager = [[CLLocationManager alloc]init];
        self.locationManager.delegate = self;
        //    self.locManager.desiredAccuracy = kCLLocationAccuracyBest;
        self.locationManager.distanceFilter = 5.0;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
        if (IOS8_OR_LATER) {
            [self.locationManager requestAlwaysAuthorization];
        }
#endif
        [self.locationManager startUpdatingLocation];
    }
//    [self loadAllDoctors];
}
#pragma  mark CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    self.locationManager.delegate=nil;
    [self.locationManager stopUpdatingLocation];
    CLLocation *loc=[locations lastObject];
    self.latitude = [NSString stringWithFormat:@"%f",loc.coordinate.latitude];
    self.longitude = [NSString stringWithFormat:@"%f",loc.coordinate.longitude];
    [self.locationManager stopUpdatingLocation];
    [self loadAllDoctors];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提醒" message:@"你必须启用定位服务,打开定位服务允许“安好”来确定你的位置." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (IOS8_OR_LATER) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }
}
#pragma mark - leftTableView和rightTableView的实现 -

-(void)makeTableView
{
    
    self.LeftTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -200, kScreenWidth / 2, 0)];
    self.leftTableView.backgroundColor = RGB(248, 248, 248);
    [self.view addSubview:self.leftTableView];
    self.leftTableView.delegate = self;
    self.leftTableView.dataSource = self;
    //隐藏横向和竖向的滑条
    self.leftTableView.showsHorizontalScrollIndicator = NO;
    self.leftTableView.showsVerticalScrollIndicator = NO;
    self.leftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.leftDataType = @[@"地区",@"职称",@"性质",@"排序"];
    self.positionArr = @[@"全部",@"主任医师",@"副主任医师",@"主治医师",@"医师",@"其他"];
    self.levelArr = @[@"全部",@"三级特等",@"三级甲等",@"三级乙等",@"三级丙等",@"二级甲等",@"二级乙等",@"二级丙等",@"一级甲等",@"一级乙等",@"一级丙等",@"对外专科",@"其他"];
    self.sortArray=@[@"全部",@"评价最高",@"咨询最多",@"离我最近"];
    self.dengjiNumArr = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12"];
    self.doclevilid = @[@"0",@"1",@"2",@"3",@"4",@"5"];
    self.sortIndex=@[@"0",@"1",@"2",@"3"];
    //左边的table
    self.RightTableView = [[UITableView alloc] initWithFrame:CGRectMake(kScreenWidth / 2, - 200, kScreenWidth / 2, 0)];
    [self.view addSubview:self.rightTableView];
    self.rightTableView.delegate = self;
    self.rightTableView.dataSource = self;
    //隐藏横向和竖向的滑条
    self.rightTableView.showsHorizontalScrollIndicator = NO;
    self.rightTableView.showsVerticalScrollIndicator = NO;
    self.rightTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.rightTableView.backgroundColor = RGB(238, 238, 238);
    
    
}
#pragma - mark searchBar
- (void)markIllnessSearchBar
{
    illSeachBar = [[FKSearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 44)];
    illSeachBar.searchTextField.placeholder = @"医生";
    illSeachBar.fkSearchRequestDelegate = self;
    [self.view addSubview:illSeachBar];
}

#pragma  mark 请求医生列表数据
- (void)loadAllDoctors
{
    
    CLAuthorizationStatus status=[CLLocationManager authorizationStatus];
    if (status==kCLAuthorizationStatusDenied||kCLAuthorizationStatusRestricted==status) {
        [self showCustomHudSingleLine:@"你必须允许“安好”来确定你的位置."];
        [self.tableview headerEndRefreshing];
        [self.tableview footerEndRefreshing];
        return;
    }
    self.page=self.page+1;
    [self showActionView];
    [self setInfowithNothing];
    NSString * requestURL = [NSString stringWithFormat:@"%@docuser/list/",kBaseURL];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSDictionary *parameters = @{@"platform": kPlatform,
                                 @"version":kVersion,
                                 @"lat":self.latitude,
                                 @"lng":self.longitude,
                                 @"keyword":keyword,
                                 @"page":[NSString stringWithFormat:@"%ld",self.page],
                                 @"departmentid":self.departmentId,
                                 @"provinceid":self.provinceid,
                                 @"doclevelid":self.doclevelid,
                                 @"hoslevelid":self.level,
                                 @"order":self.order
                                 };
    [manager POST:requestURL parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [self hiddenActionView];
        if ([self.tableview isHeaderRefreshing]) {
            [self.tableview headerEndRefreshing];

        }
        else if([self.tableview isFooterRefreshing])
        {
            [self.tableview footerEndRefreshing];
        }

        NSString *status=[NSString stringWithFormat:@"%@",[responseObject objectForKey:@"status"]];
        if ([status isEqualToString:@"1"]) {
            

            if ([[responseObject valueForKey:@"data"] count]==0) {
            }else
            {
                for (int i=0; i<[[responseObject valueForKey:@"data"] count]; i++) {
                    [self.doctorsArrays addObject:[[responseObject valueForKey:@"data"] objectAtIndex:i]];
                }
            }
            [self.tableview reloadData];
        }else
        {
            [self.tableview reloadData];
//            [self showCustomHudSingleLine:@"暂无更多数据"];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self hiddenActionView];
        [self showCustomHudSingleLine:@"暂无数据"];
        if ([self.tableview isHeaderRefreshing]) {
            [self.tableview headerEndRefreshing];
        }
        else if([self.tableview isFooterRefreshing])
        {
            [self.tableview footerEndRefreshing];
        }
        [self.rightTableView reloadData];
    }];
}
- (void)setInfowithNothing
{
    if (!self.departmentId) {
        self.departmentId=@"";
    }
    keyword=illSeachBar.searchTextField.text;

    if (!keyword) {
        keyword=@"";
    }
    if (!self.provinceid) {
        self.provinceid=@"";
    }
    if (!self.doclevelid) {
        self.doclevelid=@"";
    }
    if (!self.level) {
        self.level=@"";
    }
    if (!self.order) {
        self.order=@"";
    }

}
#pragma  mark UITableViewDatasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([tableView isEqual:self.leftTableView] ) {
    return 4;
    }
    else if ([tableView isEqual: self.rightTableView]) {
        if (leftControlRight == 100) {
            return self.rightTableArr.count;
        }else if (leftControlRight == 200){
            return self.positionArr.count;
        }else if(leftControlRight==300){
            return self.levelArr.count;
        }else return self.sortArray.count;
    }
    else return self.doctorsArrays.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (change) {
        self.leftTableCell = (LeftViewCell *)[self.leftTableView cellForRowAtIndexPath:[self.indexArr firstObject]];
    }
    if ([tableView isEqual:self.tableview]) {
        static NSString *Indentifier=@"consultdocList";
        ConsultDocListCell *cell=[tableView dequeueReusableCellWithIdentifier:Indentifier];
        if (!cell) {
            if (kScreenWidth==414) {
                cell=[[[NSBundle mainBundle]loadNibNamed:@"ConsultDocListCell" owner:self options:nil] lastObject];
            }else{
                cell=[[[NSBundle mainBundle]loadNibNamed:@"ConsultDocListCell" owner:self options:nil] objectAtIndex:0];
            }
        }
        if (self.doctorsArrays.count>0) {
            NSDictionary *doc=[self.doctorsArrays objectAtIndex:indexPath.row];
            [cell.docImage setImageWithURL:[NSURL URLWithString:[doc valueForKey:@"photourl"]] placeholderImage:[UIImage imageNamed:@"默认头像"]];
            cell.docImage.layer.cornerRadius=3.0;
            cell.docImage.layer.masksToBounds=YES;
            cell.docName.text=[doc valueForKey:@"username"];
            NSString *str;
            if ([[doc valueForKey:@"doclevelid"]  isEqualToString:@"0"]) {
                str=@"主任医师";
            }else if ([[doc valueForKey:@"doclevelid"] isEqualToString:@"1"])
            {
                str=@"副主任医师";
                
            }else if ([[doc valueForKey:@"doclevelid"] isEqualToString:@"2"]){
                str=@"主治医师";
            }
            else if ([[doc valueForKey:@"doclevelid"] isEqualToString:@"3"]){
                str=@"医师";
            }
            else{
                str=@"其他";
            }
            cell.docHospital.text=[NSString stringWithFormat:@"%@%@",[doc valueForKey:@"hospitalname"],str];
            cell.distance.text=[NSString stringWithFormat:@"%@m",[doc valueForKey:@"distance"]];
            cell.docExpert.text=[NSString stringWithFormat:@"擅长：%@",[doc valueForKey:@"expertise"]];
            if ([[NSString stringWithFormat:@"%@",[doc valueForKey:@"isallow"]] isEqualToString:@"1"]) {
                cell.onlineStatus.text=@"咨询中";
                cell.onlineImage.backgroundColor=[ClassMethodsViewController colorWithHexString:@"#4fc1e9"];
            }else
            {
                cell.onlineStatus.text=@"离线";
                cell.onlineImage.backgroundColor=[ClassMethodsViewController colorWithHexString:@"#717171"];
            }
            cell.docGood.text=[NSString stringWithFormat:@"赞（%@）",[doc valueForKey:@"good"]];
            cell.peerAuthor.text=[NSString stringWithFormat:@"同行认证（%@）",[doc valueForKey:@"agree"]];
            cell.docFans.text=[NSString stringWithFormat:@"粉丝（%@）",[doc valueForKey:@"follower"]];

        }
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;

    }else if([tableView isEqual:self.rightTableView])
    {
        static NSString *indentify = @"rightCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentify];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentify];
        }
        
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.backgroundColor = RGB(238, 238, 238);
        if (leftControlRight == 100) {
            if (indexPath.row == 0) {
                cell.textLabel.text = [NSString stringWithFormat:@"全部"];
            }else{
                MyNSLog("%@", self.rightTableArr );

                if (self.rightTableArr.count>0) {
                    cell.textLabel.text = [NSString stringWithFormat:@"%@",[self.rightTableArr[indexPath.row - 1] objectForKey:@"name"]];

                }
            }
        }else if (leftControlRight == 200){
            cell.textLabel.text = self.positionArr[indexPath.row];
        }else if(leftControlRight==300){
            cell.textLabel.text = self.levelArr[indexPath.row];
        }
        else
        {
            cell.textLabel.text=self.sortArray[indexPath.row];
        }
        change = NO;
        return cell;
    }else
    {
        static NSString *indentify = @"leftCell";
        LeftViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentify];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"LeftViewCell" owner:self options:nil] lastObject];
        }
        cell.lineView.backgroundColor = [ClassMethodsViewController colorWithHexString:@"#cccccc"];
        if (indexPath.row == 0) {
            cell.backgroundColor = RGB(238, 238, 238);
            [self.indexArr addObject:indexPath];
            cell.lineView.hidden = YES;
        }else{
            cell.backgroundColor = RGB(248, 248, 248);
        }
        if (self.leftDataType.count>0) {
            @try {
               cell.typeLabel.text =  self.leftDataType[indexPath.row];
            }
            @catch (NSException *exception) {
                MyNSLog("%@",exception);
            }
            cell.typeLabel.text = self.leftDataType[indexPath.row];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    }
}
#pragma Mark UItableviewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.leftTableView || tableView == self.rightTableView) {
        return 35;
    }
    else {
        if (kScreenWidth==414) {
            return 156;
        }
        return 130.f;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (tableView == self.leftTableView || tableView == self.rightTableView) {
        return 10;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (tableView == self.leftTableView || tableView == self.rightTableView) {
        return 5;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
    view.backgroundColor = [UIColor lightGrayColor];
    if (tableView == self.leftTableView) {
        view.backgroundColor = RGB(248, 248, 248);
        return view;
    }
    if (tableView == self.rightTableView) {
        view.backgroundColor = RGB(238, 238, 238);
        return view;
    }
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
    view.backgroundColor = [UIColor lightGrayColor];
    if (tableView == self.leftTableView) {
        view.backgroundColor = RGB(248, 248, 248);
        return view;
    }
    if (tableView == self.rightTableView) {
        view.backgroundColor = RGB(238, 238, 238);
        return view;
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView isEqual: self.leftTableView]) {
        LeftViewCell *leftcell = (LeftViewCell *)[self.leftTableView cellForRowAtIndexPath:indexPath];
        self.leftTableCell.contentView.backgroundColor = RGB(248, 248, 248);
        leftcell.contentView.backgroundColor = RGB(238, 238, 238);
        
        if (indexPath.row == 0) {
            [self.rightTableArr removeAllObjects];
            leftControlRight = 100;
            leftcell.lineView.hidden = YES;
            self.leftTableCell.lineView.hidden = NO;
            [self loadDataDepartment];
        }else if (indexPath.row == 1){
            leftControlRight = 200;
            leftcell.lineView.hidden = YES;
            self.leftTableCell.lineView.hidden = NO;
            [self.rightTableView reloadData];
        }else if(indexPath.row==2){
            leftControlRight = 300;
            leftcell.lineView.hidden = YES;
            self.leftTableCell.lineView.hidden = NO;
            [self.rightTableView reloadData];
        }else
        {
            leftControlRight=400;
            leftcell.lineView.hidden = YES;
            self.leftTableCell.lineView.hidden = NO;
            [self.rightTableView reloadData];
        }
        
        if ([leftcell isEqual:self.leftTableCell]) {
            leftcell.lineView.hidden = YES;
        }
        self.leftTableCell = (LeftViewCell *)[self.leftTableView cellForRowAtIndexPath:indexPath];
        self.leftTableCell = leftcell;
        return;
    }
    
    else if ([tableView isEqual: self.rightTableView]) {
        if (leftControlRight == 100) {
            if (indexPath.row == 0) {
                self.seekAddrStr = [NSString stringWithFormat:@"全部"];
                self.provinceid=@"0";
            }else{
                self.seekAddrStr = [NSString stringWithFormat:@"%@",[self.rightTableArr[indexPath.row - 1] objectForKey:@"name"]];
                self.cityid = [NSString stringWithFormat:@"%@",[self.rightTableArr[indexPath.row - 1] objectForKey:@"cityid"]];
                self.provinceid = [NSString stringWithFormat:@"%@",[self.rightTableArr[indexPath.row - 1] objectForKey:@"provinceid"]];
                
            }
            self.rightTableCell.contentView.backgroundColor = RGB(238, 238, 238);
            self.leftTableCell.nameLabel.text = self.seekAddrStr;
            
            [self.rightTableView cellForRowAtIndexPath:indexPath].contentView.backgroundColor = RGB(226, 226, 226);;
            self.rightTableCell = [self.rightTableView cellForRowAtIndexPath:indexPath];
        }else if (leftControlRight == 200){
            [self.rightTableArr removeAllObjects];
            self.positionStr = [NSString stringWithFormat:@"%@",self.positionArr[indexPath.row]];
            self.doclevelid = [NSString stringWithFormat:@"%@",self.doclevilid[indexPath.row]];
            self.rightTableCell.contentView.backgroundColor = RGB(238, 238, 238);
            self.leftTableCell.nameLabel.text = self.positionStr;
            MyNSLog("%@", self.positionStr);
            [self.rightTableView cellForRowAtIndexPath:indexPath].contentView.backgroundColor = RGB(226, 226, 226);;
            self.rightTableCell = [self.rightTableView cellForRowAtIndexPath:indexPath];
            
        }else if(leftControlRight==300){
            [self.rightTableArr removeAllObjects];
            self.dengJiStr = [NSString stringWithFormat:@"%@",self.levelArr[indexPath.row]];
            self.level = [NSString stringWithFormat:@"%@",self.dengjiNumArr[indexPath.row]];
            self.rightTableCell.contentView.backgroundColor = RGB(238, 238, 238);
            self.leftTableCell.nameLabel.text = self.dengJiStr;
            MyNSLog("%@", self.dengJiStr);
            [self.rightTableView cellForRowAtIndexPath:indexPath].contentView.backgroundColor = RGB(226, 226, 226);;
            self.rightTableCell = [self.rightTableView cellForRowAtIndexPath:indexPath];
        }
        else{
            [self.rightTableArr removeAllObjects];
            self.dengJiStr = [NSString stringWithFormat:@"%@",self.sortArray[indexPath.row]];
            self.order = [NSString stringWithFormat:@"%@",self.sortIndex[indexPath.row]];
            self.rightTableCell.contentView.backgroundColor = RGB(238, 238, 238);
            self.leftTableCell.nameLabel.text = self.dengJiStr;
//            MyNSLog("%@", self.dengJiStr);
            [self.rightTableView cellForRowAtIndexPath:indexPath].contentView.backgroundColor = RGB(226, 226, 226);;
            self.rightTableCell = [self.rightTableView cellForRowAtIndexPath:indexPath];
        }
        return;
    }
    else if ([self.tableview isEqual:tableView])
    {
        if([self.doctorsArrays count]>0)
        {
            DocInfoViewController *docInfo=[[DocInfoViewController alloc]initWithNibName:@"DocInfoViewController" bundle:[NSBundle mainBundle]];
            docInfo.doctoruid=[[self.doctorsArrays objectAtIndex:indexPath.row] valueForKey:@"uid"];
            for ( UIViewController *controller in self.navigationController.viewControllers) {
                if ([controller isKindOfClass:[ConsultViewController class]]) {
                    ConsultViewController *consult=(ConsultViewController *)controller;
                    //            consult.docInfo=self.docInfo;
                    //            self.docDelegate=consult;
                    //            [self.navigationController popToViewController:controller animated:YES];
                    docInfo.docDelegate=consult;
                }
            }
            if (self.isFromConsult) {
                docInfo.isFromConsult=YES;
            }
            [self.navigationController pushViewController:docInfo animated:YES];
        }
    }
    
    
}
#pragma mark 返回上一页
- (void)backClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma  mark 筛选
- (void)rightButtonClicked
{
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/**
 *  点击“筛选” 按钮图标换成“完成”
 *   下拉-选项列表 
 */
-(void)filterBtnDown
{
    [illSeachBar.searchTextField resignFirstResponder];
    [self makeRightFilterFinishItem];
    [self loadDataDepartment];
    [UIView animateWithDuration:0.2 animations:^{
        self.leftTableView.frame = CGRectMake(0, 0, kScreenWidth / 2, 200);
        self.rightTableView.frame = CGRectMake(kScreenWidth / 2, 0, kScreenWidth / 2, 200);
        self.longVerticalLineView.frame = CGRectMake(kScreenWidth / 2 - 0.5, 150, 0.5, 50);
    }];
    [self.view addSubview:self.maskViews];
    [self.view addSubview:self.transverseLineView];
    [self.view addSubview:self.shotVerticalLineView];
    [self.view addSubview:self.longVerticalLineView];

}
/**
 *  点击"完成"图标变回“筛选”
 *  选项列表收回
 */
-(void)filterFinishDown
{
    
    [self makeRightFilterItem];
    [UIView animateWithDuration:0.2 animations:^{
        self.leftTableView.frame = CGRectMake(0, -200, kScreenWidth / 2, 200);
        self.rightTableView.frame = CGRectMake(kScreenWidth / 2,-200, kScreenWidth / 2, 200);
        self.longVerticalLineView.frame = CGRectMake(kScreenWidth / 2 - 0.5, 150, 0, 0);
    }];
    [self.maskViews removeFromSuperview];
    [self.transverseLineView removeFromSuperview];
    [self.shotVerticalLineView removeFromSuperview];
    [self.longVerticalLineView removeFromSuperview];
    self.page = 0;
    [self.doctorsArrays removeAllObjects];
    [self loadAllDoctors];
}

- (void)packUpView{
    [self makeRightFilterItem];
    [UIView animateWithDuration:0.2 animations:^{
        self.leftTableView.frame = CGRectMake(0, -200, kScreenWidth / 3, 200);
        self.rightTableView.frame = CGRectMake(kScreenWidth/3,-200, kScreenWidth/3 * 2, 200);
    }];
    [self.maskViews removeFromSuperview];
    [self.transverseLineView removeFromSuperview];
    [self.shotVerticalLineView removeFromSuperview];
    [self.longVerticalLineView removeFromSuperview];


}
- (NSMutableArray *)rightTableArr{
    if (_rightTableArr == nil) {
        self.rightTableArr = [NSMutableArray array];
    }
    return _rightTableArr;
}


- (NSMutableArray *)indexArr{
    if (_indexArr == nil) {
        self.indexArr = [NSMutableArray array];
    }
    return _indexArr;
}

- (UITableViewCell *)rightTableCell{
    if (_rightTableCell == nil) {
        _rightTableCell = [[UITableViewCell alloc] init];
    }
    return _rightTableCell;
}

- (LeftViewCell *)leftTableCell{
    if (_leftTableCell == nil) {
        _leftTableCell = [[LeftViewCell alloc] init];
    }
    return _leftTableCell;
}

- (NSArray *)dengjiNumArr{
    if (_dengjiNumArr == nil) {
        _dengjiNumArr = [NSArray array];
    }
    return _dengjiNumArr;
}

- (UIView *)maskViews{
    if (_maskViews == nil) {
        _maskViews = [[UIView alloc] initWithFrame:CGRectMake(0, 200, kScreenWidth, kScreenHeight - 264)];
        _maskViews.alpha = 0.5;
        _maskViews.backgroundColor = [UIColor lightGrayColor];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(packUpView)];
        tap.numberOfTapsRequired = 1;
        [_maskViews addGestureRecognizer:tap];
    }
    return _maskViews;
}
-(void)makeRightFilterItem
{
    UIBarButtonItem *filterBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_筛选.png"] style:UIBarButtonItemStylePlain target:self action:@selector(filterBtnDown)];
    filterBtnItem.tintColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = filterBtnItem;
}
//“完成”
-(void)makeRightFilterFinishItem
{
    UIBarButtonItem *filterBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_完成.png"] style:UIBarButtonItemStylePlain target:self action:@selector(filterFinishDown)];
    filterBtnItem.tintColor = [UIColor whiteColor];
    filterBtnItem.tag = 100;
    self.navigationItem.rightBarButtonItem = filterBtnItem;
}
#pragma mark - 数据加载
-(void)loadDataDepartment
{
    [self showActionView];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
    [dict setObject:kPlatform forKey:@"platform"];
    [dict setObject:kVersion forKey:@"version"];
    [dict setValue:@"2" forKey:@"returnType"];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:[NSString stringWithFormat:@"%@wiki/area/",kBaseURL] parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];
        [self hiddenActionView];
        if ([statusString isEqualToString:@"0"]) {
            [self shouLabel:@"暂无内容"];
        }else{
            NSArray *jsonDictArr = [[responseObject objectForKey:@"data"] isEqual:[NSNull null]]?nil:[responseObject objectForKey:@"data"];
            //            MyNSLog("%@", jsonDictArr);
            for (NSDictionary *objc in jsonDictArr) {
                [self.rightTableArr addObject:objc];
            }
        }
        [self.rightTableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self hiddenActionView];
        [self.rightTableView reloadData];
    }];
    
}
#pragma - mark FKSearchDelegate
/**
 *  FKSearch的delegate
 */
- (void)VoiceConversion
{
    [illSeachBar.searchTextField resignFirstResponder];
    [self starVoice];
}
- (void)voice:(NSString *)voice
{
    illSeachBar.searchTextField.text = voice;
    keyword=illSeachBar.searchTextField.text;
//    departmentBool = NO;
//    self.isSearch = YES;
    self.page = 0;
//    self.searchdocdor = voice;
    [self.doctorsArrays removeAllObjects];

    [self loadAllDoctors];
}
- (void)SearchString;
{
    [illSeachBar.searchTextField resignFirstResponder];
    keyword=illSeachBar.searchTextField.text;
    self.page = 0;
    [self.doctorsArrays removeAllObjects];
    [self loadAllDoctors];

}



- (UIView *)transverseLineView{
    if (_transverseLineView == nil) {
        _transverseLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 199.5, kScreenWidth, 0.5)];
        _transverseLineView.backgroundColor = [ClassMethodsViewController colorWithHexString:@"#cccccc"];
    }
    return _transverseLineView;
}

- (UIView *)shotVerticalLineView{
    if (_shotVerticalLineView == nil) {
        _shotVerticalLineView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 0.5 , 0, 0.5, 10)];
        _shotVerticalLineView.backgroundColor = [ClassMethodsViewController colorWithHexString:@"#cccccc"];
    }
    return _shotVerticalLineView;
}

- (UIView *)longVerticalLineView{
    if (_longVerticalLineView == nil) {
        _longVerticalLineView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 0.5, 150, 0.5, 50)];
        _longVerticalLineView.backgroundColor = [ClassMethodsViewController colorWithHexString:@"#cccccc"];
    }
    return _longVerticalLineView;
}
- (void)loadAllDoctorspage
{
    self.page=0;
    [self.doctorsArrays removeAllObjects];
    [self loadAllDoctors];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
